fix: usage-card success rate overflow (成功率保留 2 位小数) - #1
Open
Tony-ooo wants to merge 1 commit into
Open
Conversation
The account-usage card rendered the API's full-precision success rate raw (e.g. 99.9882890268181%), which exceeded the stat tile and pushed past the card edge. Unlike the neighbouring stats, the success rate had no display formatter, and the stat value CSS had no overflow guard. - add formatPercent() (2 decimals) beside the other formatters - render the success rate through it in the settings-page card - harden .cc-usageStat/.cc-usageStatValue with min-width:0 and overflow-wrap:anywhere so long values wrap instead of overflowing - apply the same 2-decimal rounding to the /commandcode command line - cover formatPercent and the updated command output in tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
中文
现象 / Symptom
设置页「账户用量」卡片的成功率一栏显示全精度小数(例如
99.9882890268181%),数字溢出统计格子并超出卡片右缘(在小窗口下尤其明显)。同卡片的其它统计(花费$34.6038、Token839.1M等)均正常。根因 / Root cause
两处叠加造成:
/alpha/usage/summary返回的successRate是全精度浮点数,Host 端src/adapter.ts只做numberValue(...) ?? 0透传;浏览器端src/client/section.tsx直接字符串插值`${report.usage.successRate}%`—— 没有toFixed()。同卡片其余三项全部走formatMoney/formatMoneyExact/formatTokensCompact格式化。.cc-usageStat是 flex column,外层网格轨道minmax(120px, 1fr);.cc-usageStatValue没有min-width: 0/overflow-wrap,一个 16 字符的连续数字串是不可断行单元,min-content 宽度超过轨道最小宽度后直接横向溢出。修复 / Fix
src/client/usage.ts:新增formatPercent()(保留 2 位小数,与其它格式化器并列)。src/client/section.tsx:成功率改为formatPercent(report.usage.successRate)渲染。src/client/index.ts:.cc-usageStat/.cc-usageStatValue增加min-width: 0与overflow-wrap: anywhere,任何超长数字回退为换行而不是破框。src/commands.ts:/commandcode命令行的成功率同步为toFixed(2),与卡片口径一致。tests/:新增formatPercent用例,并更新命令输出的断言。验证 / Verification
npm run typecheck通过npm test282/282 通过npm run build重建产物,已确认 bundle 中不再有裸插值English
Symptom: The account-usage card's success rate renders the API's full-precision float (e.g.
99.9882890268181%), overflowing the stat tile and the card edge, while every other stat (cost$34.6038, tokens839.1M, …) renders fine.Root cause (two compounding layers):
src/client/section.tsxinterpolates`${report.usage.successRate}%`raw, while the neighbouring stats all go throughformatMoney/formatTokensCompact..cc-usageStatValuelacksmin-width: 0/overflow-wrap, so the 16-char unbreakable number exceeds theminmax(120px, 1fr)grid track and spills out horizontally.Fix:
formatPercent()(2 decimals) insrc/client/usage.tsand use it in the card..cc-usageStat/.cc-usageStatValuewithmin-width: 0+overflow-wrap: anywhereso any long value wraps instead of overflowing./commandcodecommand-line success rate to the same 2 decimals.formatPercentcases + updated command-output assertions.Verification:
npm run typecheckclean ·npm test282/282 pass · rebuilt bundle no longer contains the raw interpolation.